package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.member.client.MemberManageClient;
import com.woniuxy.member.client.MemberQueryClient;
import com.woniuxy.member.client.param.AddMemberCouponParam;
import com.woniuxy.member.client.param.ExchangeCouponSearchParam;
import com.woniuxy.member.client.param.ModifyMemberCouponParam;
import com.woniuxy.member.client.result.ExchangeCouponClientDto;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.MemberCouponClient;
import com.woniuxy.store.client.param.MemberExchangeParam.AddMemberCouponParams;
import com.woniuxy.store.client.param.MemberExchangeParam.ExchangeCouponSearchParams;
import com.woniuxy.store.client.param.MemberExchangeParam.ModifyMemberCouponParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/store/marketing")
public class MemberCouponClientImpl implements MemberCouponClient {
    @Autowired
    private MemberManageClient memberManageClient;
    @Autowired
    private MemberQueryClient memberQueryClient;
    @Override
    public Result getScoreExchangeCoupon(@Valid ExchangeCouponSearchParams exchangeCouponSearchParams) {
        ExchangeCouponSearchParam exchangeCouponSearchParam = BeanUtil.toBean(exchangeCouponSearchParams, ExchangeCouponSearchParam.class);
        exchangeCouponSearchParam.setStoreId(StoreIdUtil.getFromToken());
        Result<List<ExchangeCouponClientDto>> scoreExchangeCoupon = memberQueryClient.getScoreExchangeCoupon(exchangeCouponSearchParam);
        return scoreExchangeCoupon;
    }

    @Override
    public Result addMemberCoupon(@Valid AddMemberCouponParams addMemberCouponParams) {
        AddMemberCouponParam addMemberCouponParam = BeanUtil.toBean(addMemberCouponParams, AddMemberCouponParam.class);
        addMemberCouponParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = memberManageClient.addMemberCoupon(addMemberCouponParam);
        return result;
    }

    @Override
    public Result modifyMemberCoupon(@Valid ModifyMemberCouponParams modifyMemberCouponParams) {
        ModifyMemberCouponParam modifyMemberCouponParam = BeanUtil.toBean(modifyMemberCouponParams, ModifyMemberCouponParam.class);
        modifyMemberCouponParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = memberManageClient.modifyMemberCoupon(modifyMemberCouponParam);
        return result;
    }

    @Override
    public Result delMemberCoupon(Integer exchangeCouponId) {
        memberManageClient.delMemberCoupon(StoreIdUtil.getFromToken(),exchangeCouponId);
        return null;
    }
}
